﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using System.Linq;
using System.Text;

namespace Space_Cleaner.SpaceCleaner
{
    class SC_SpaceObjectList
    {
        private static int MAX_TRASH = 1000;
        private static List<SC_Trash> TrashList = null;

        public static void Initialize()
        {
            if (TrashList == null)
            {
                TrashList = new List<SC_Trash>(MAX_TRASH);
                for (int i = 0; i < MAX_TRASH; i++)
                {
                    SC_Trash Trash = new SC_Trash();
                    Trash.Texture = SC_TextureManager.getTexture("schrott1");
                    TrashList.Add(Trash);
                }
            }
            else
            {
                MAX_TRASH = TrashList.Count;
            }
        }

        public static SC_Trash GetNewTrash()
        {
            SC_Trash Trash = null;
            if (TrashList.Count > 0)
            {
                Trash = TrashList[TrashList.Count - 1];
            }
            else if (TrashList.Count < 0)
            {
                int MAX_TRASH_HALBE = MAX_TRASH / 2;
                for (int i = 0; i < MAX_TRASH_HALBE; i++)
                {
                    SC_Trash TempTrash = new SC_Trash(Vector2.Zero, 0.0f, null);
                    TempTrash.Texture = SC_TextureManager.getTexture("schrott1");
                    TrashList.Add(TempTrash);
                }
                MAX_TRASH *= MAX_TRASH_HALBE;
                Trash = TrashList[TrashList.Count - 1];
            }
            TrashList.Remove(Trash);
            return Trash;
        }

        public static void GiveTrashBack(SC_Trash _Trash)
        {
            TrashList.Add(_Trash);
            _Trash = null;
            if (TrashList.Count > MAX_TRASH)
            {
                MAX_TRASH = TrashList.Count;
            }
        }
    }
}
